#include "GpsInfoPage.h"

#include "GpsSensor.h"



GpsInfoPage::GpsInfoPage(const int pageNum) : BasePage(pageNum) {
    mpControllers = &ExtendDeviceManagerSingleton::instance().getExtendDevices(ExtendDeviceEnum::GPS);
}


void GpsInfoPage::paint() {
    std::string content[4];

    resetStream();

    strStream << std::left << std::setw(13) << "GpsInfo" << std::right << std::setw(3) << pageNum;
    content[0] = strStream.str();

    if (mpControllers->empty() ) {
        content[1] = ExtendDeviceEnum::NO_DEVICE.name;
    } else {
        ExtendDevicePtr extendDevicePtr = mpControllers->front().lock();
        if (nullptr == extendDevicePtr) {
            content[1] = ExtendDeviceEnum::NO_DEVICE.name;
        } else {

            GpsSensor* gpsController = static_cast<GpsSensor*> (extendDevicePtr->getDevice(ExtendDeviceEnum::GPS));

            content[1] = gpsController->longitude;
            content[1].append(1, gpsController->longitudeSymbol);

            content[2] = gpsController->latitude;
            content[2].append(1, gpsController->latitudeSymbol);

            resetStream();
            strStream << "sigNo:" << std::right<< std::setw(2) << gpsController->signalNoise;
            strStream << "satel:" << gpsController->satelliteQuantity;
            content[3] = strStream.str();
        }

    }
    screen.show(&content[0], &content[1], &content[2], &content[3]);
}




